package com.ruoyi.web.controller.qianhuankuan;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.qianhuankuan.domain.Qianhuankuan;
import com.ruoyi.qianhuankuan.service.IQianhuankuanService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 欠还款Controller
 *
 * @author ruoyi
 * @date 2023-05-25
 */
@RestController
@RequestMapping("/system/qianhuankuan")
public class QianhuankuanController extends BaseController
{
    @Autowired
    private IQianhuankuanService qianhuankuanService;

    /**
     * 查询欠还款列表
     */
    @PreAuthorize("@ss.hasPermi('system:qianhuankuan:list')")
    @GetMapping("/list")
    public TableDataInfo list(Qianhuankuan qianhuankuan)
    {
        startPage();
        List<Qianhuankuan> list = qianhuankuanService.selectQianhuankuanList(qianhuankuan);
        return getDataTable(list);
    }

    /**
     * 导出欠还款列表
     */
    @PreAuthorize("@ss.hasPermi('system:qianhuankuan:export')")
    @Log(title = "欠还款", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Qianhuankuan qianhuankuan)
    {
        List<Qianhuankuan> list = qianhuankuanService.selectQianhuankuanList(qianhuankuan);
        ExcelUtil<Qianhuankuan> util = new ExcelUtil<Qianhuankuan>(Qianhuankuan.class);
        util.exportExcel(response, list, "欠还款数据");
    }

    /**
     * 获取欠还款详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:qianhuankuan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(qianhuankuanService.selectQianhuankuanById(id));
    }

    /**
     * 新增欠还款
     */
    @PreAuthorize("@ss.hasPermi('system:qianhuankuan:add')")
    @Log(title = "欠还款", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Qianhuankuan qianhuankuan)
    {
        return toAjax(qianhuankuanService.insertQianhuankuan(qianhuankuan));
    }

    /**
     * 修改欠还款
     */
    @PreAuthorize("@ss.hasPermi('system:qianhuankuan:edit')")
    @Log(title = "欠还款", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Qianhuankuan qianhuankuan)
    {
        return toAjax(qianhuankuanService.updateQianhuankuan(qianhuankuan));
    }

    /**
     * 删除欠还款
     */
    @PreAuthorize("@ss.hasPermi('system:qianhuankuan:remove')")
    @Log(title = "欠还款", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(qianhuankuanService.deleteQianhuankuanByIds(ids));
    }
}
